package org.excample.config;

import org.excample.interceptors.LoginInterceptors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//当前类是一个配置类，该类优先级最高，在项目启动时加载
public class WebConfig implements WebMvcConfigurer {//用于web请求响应时的配置，一个类实现该接口该类就被称为配置类
    @Autowired
    private LoginInterceptors loginInterceptors;//将自定义拦截器注入到该配置类中

    @Override
    public void addInterceptors(InterceptorRegistry registry) {//添加拦截器实例方法，参数：注册拦截器对象
        //addInterceptor添加拦截器
        //excludePathPatterns放行地址
        registry.addInterceptor(loginInterceptors).excludePathPatterns("/user/login","/user/register");
    }
}
